﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="ArtistsManagers.aspx.cs" Inherits="ImgForecast.admin.ArtistsManagers" %>

<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="cc1" %>
<%@ Register Assembly="obout_Interface" Namespace="Obout.Interface" TagPrefix="cc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <cc1:Grid ID="Grid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        AllowGrouping="true" GroupBy="LoweredUserName" r>
        <Columns>
            <cc1:Column DataField="ArtistID" HeaderText="Artist" Width="200">
                <TemplateSettings TemplateId="ArtistTemplate" EditTemplateId="ArtistEditTemplate" />
            </cc1:Column>
            <cc1:Column DataField="UserID" HeaderText="UserID" Width="400" Visible="true" AllowEdit="false">
                <TemplateSettings TemplateId="UserTemplate" EditTemplateId="UserEditTemplate" />
            </cc1:Column>
            <cc1:Column DataField="LoweredUserName" HeaderText="Manager" Width="200" Visible="false">
            </cc1:Column>
            <cc1:Column HeaderText="Edit" AllowEdit="true" AllowDelete="true" Width="125" runat="server" />
        </Columns>
        <Templates>
            <cc1:GridTemplate runat="server" ID="UserTemplate">
                <Template>
                    <%# Container.DataItem["LoweredUserName"]%>
                </Template>
            </cc1:GridTemplate>
            <cc1:GridTemplate runat="server" ID="GroupTemplate">
                <Template>
                    <%# Container.DataItem["LoweredUserName"]%>
                </Template>
            </cc1:GridTemplate>
            <cc1:GridTemplate runat="server" ID="UserEditTemplate" ControlID="ddlUser" ControlPropertyName="value">
                <Template>
                    <cc2:OboutDropDownList ID="ddlUser" runat="server" DataSourceID="SqlDataSource2"
                        DataTextField="LoweredUserName" DataValueField="UserID">
                    </cc2:OboutDropDownList>
                </Template>
            </cc1:GridTemplate>
            <cc1:GridTemplate runat="server" ID="ArtistTemplate">
                <Template>
                    <%# Container.DataItem["ArtistName"]%>
                </Template>
            </cc1:GridTemplate>
            <cc1:GridTemplate runat="server" ID="ArtistEditTemplate" ControlID="ddlArtist" ControlPropertyName="value">
                <Template>
                    <cc2:OboutDropDownList ID="ddlArtist" runat="server" DataSourceID="SqlDataSource3"
                        DataTextField="ArtistName" DataValueField="ArtistID">
                    </cc2:OboutDropDownList>
                </Template>
            </cc1:GridTemplate>
        </Templates>
    </cc1:Grid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        DeleteCommand="DELETE FROM [ArtistsManagers] WHERE [UserID] = @UserID AND [ArtistID] = @ArtistID"
        InsertCommand="INSERT INTO [ArtistsManagers] ([UserID], [ArtistID]) VALUES (@UserID, @ArtistID)"
        SelectCommand="SELECT     ArtistsManagers.UserID, ArtistsManagers.ArtistID, aspnet_Users.LoweredUserName, Artists.Lastname + ', ' + Artists.Firstname AS ArtistName, 
                      aspnet_Roles.LoweredRoleName
FROM         ArtistsManagers INNER JOIN
                      aspnet_Users ON ArtistsManagers.UserID = aspnet_Users.UserId INNER JOIN
                      Artists ON ArtistsManagers.ArtistID = Artists.ArtistID INNER JOIN
                      aspnet_UsersInRoles ON aspnet_Users.UserId = aspnet_UsersInRoles.UserId INNER JOIN
                      aspnet_Roles ON aspnet_UsersInRoles.RoleId = aspnet_Roles.RoleId
WHERE     (aspnet_Roles.LoweredRoleName = 'Manager')
 ORDER BY LoweredUserName">
        <DeleteParameters>
            <asp:Parameter Name="UserID" Type="String" />
            <asp:Parameter Name="ArtistID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="UserID" Type="String" />
            <asp:Parameter Name="ArtistID" Type="Int32" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        SelectCommand="SELECT [LoweredUserName], [UserID] FROM [aspnet_Users] ORDER BY [LoweredUserName]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        SelectCommand="SELECT Artists.Lastname + ', ' + Artists.Firstname AS ArtistName, ArtistID FROM Artists ORDER BY ArtistName">
    </asp:SqlDataSource>
</asp:Content>
